home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ8801.ZIP
/
HOLUB.ZIP
/
HOLUB.EXP
Wrap
Text File
|
1987-10-29
|
6KB
|
168 lines
________________________________________________________________
Fig. 1:
+-----------------------------+
| tasks |
| +-----------------------+ |
| | kernel | |
| | +-----------------+ | |
| | | I/O system | | |
| | | +-----------+ | | |
| | | | interrupt | | | |
| | | | system | | | |
| | | +-----------+ | | |
| | +-----------------+ | |
| +-----------------------+ |
+-----------------------------+
+-----------------------+-------+
| kernel | |
+-----------+-----------+ |
| | DOS | tasks |
| +--------+ | |
| interrupt | I/O | | |
| system | system | | |
| | | | |
+-----------+--------+--+-------+
________________________________________________________________
_______________________________________________________________
Example 1:
typedef struct tcb
{
void **sp; /* Task-swap stuff */
unsigned ss;
unsigned priority;
unsigned long timestamp;
unsigned wait; /* Message-management
stuff */
struct tcb *next;
void *msg;
int status; /* debugging stuff */
char *tag;
void **initial_sp
void *stack[1]; /* Base of system stack
*/
}
TCB;
________________________________________________________________
________________________________________________________________
Fig. 2:
+---------------+
| TCB structure |
+---------------+
| |
| |
| task's |
| stack |
| |
| |
| |
| |
+---------------+
________________________________________________________________
________________________________________________________________
Example 2:
typedef struct t_queue
{
int signature;
struct t_queue *next;
TCB *task_h; /* Task queue */
TCB *task_t;
int q_size; /* Message queue */
int numele;
void **headp;
void **tailp;
void *queue[1];
}
T_QUEUE;
________________________________________________________________
_______________________________________________________________
Fig. 3:
T_QUEUE T_QUEUE
+----------+ +----------+
T_queues--->| next----|------------------>| next (0) |
| | | |
+-------|--t_head | +-------|--tailp |
| | t_tail--|--+ | +----|--headp |
| +----------+ | | | +----------+
| | | +--->|
*----|-->"message 1"
| | | +----------+
| TCB | | |
*----|-->"message 2"
| +--------+ | | +----------+
+-->| next | | +------>|
*----|-->"message 3"
| | | | +----------+
+----|---+ | |space for |
| | | other |
| | | messages |
TCB V | +----------+
+--------+ |
| next |<-------+
| (0) |
+--------+
A list of two queues, the first of which has two tasks waiting at
it and the second of which has three messages enqueued and no
tasks waiting. Only relevant fields are shown.
________________________________________________________________
_______________________________________________________________
Example 3:
void *pq_look( queue )
PQ *queue;
{
return queue->nitems ? queue->heap : NULL ;
}
/*--------------------------------------------*/
int pq_replace( p, target, item )
PQ *p;
void *item, *target;
{
int slots_in_use;
if( slots_in_use = p->nitems )
{
memcpy( target, p->heap, p->itemsize );
memcpy( p->heap, item, p->itemsize );
reheap_down( p, p->heap );
}
return slots_in_use ;
}
________________________________________________________________